package com.waiting.leetcode;

/**
 * @Description
 * @Author bjweitingting
 * @Date 2019/3/12
 **/
public class CompareVersionNumbers165 {
    public static void main(String[] args) {
        String s1 = "7.5.3.0", s2 = "7.5.3";
        System.out.println(compareVersion(s1, s2));
    }

    public static int compareVersion(String version1, String version2) {
        String[] v1 = version1.split("\\.");
        String[] v2 = version2.split("\\.");
        int i = 0, j = 0;
        for (; i < v1.length && j < v2.length; i++, j++) {
            if (v1[i].equals(v2[j])) {
                continue;
            } else {
                Integer v1Tmp = Integer.valueOf(v1[i]);
                Integer v2Tmp = Integer.valueOf(v2[j]);
                if (v1Tmp == v2Tmp) {
                    continue;
                } else {
                    return v1Tmp > v2Tmp ? 1 : -1;
                }
            }
        }
        if (v1.length == v2.length) {
            return 0;
        } else {
            while (i != v1.length) {
                Integer v1Tmp = Integer.valueOf(v1[i]);
                if (v1Tmp > 0) {
                    return 1;
                }
                i++;
            }
            while (j != v2.length) {
                Integer v2Tmp = Integer.valueOf(v2[j]);
                if (v2Tmp > 0) {
                    return -1;
                }
                j++;
            }
            return 0;
        }
    }
}
